package com.travelsmart.client.apresentacao.view.subview;

import com.google.gwt.maps.client.InfoWindowContent;
import com.google.gwt.maps.client.MapWidget;
import com.google.gwt.maps.client.control.LargeMapControl;
import com.google.gwt.maps.client.geom.LatLng;
import com.google.gwt.maps.client.overlay.Marker;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.travelsmart.client.apresentacao.i18n.I18nMessages;
import com.travelsmart.client.apresentacao.view.BaseView;
import com.travelsmart.client.bean.to.HotelTO;

//# EXERC. 4 TODO: Exercio 4
public class ViewMapHotel extends BaseView {
	private final VerticalPanel vPanelViewMapHotel = new VerticalPanel();

	public ViewMapHotel() {
		super(new HTML());
		initWidget(vPanelViewMapHotel);
	}

	public void exec(final HotelTO hotel) {
		vPanelViewMapHotel.clear();
		if (hotel.getLatitude() != null) {
			LatLng ATLANTA = LatLng.newInstance(Double.parseDouble(hotel
					.getLatitude()), Double.parseDouble(hotel.getLongitude()));
			if (ATLANTA != null) {
				final MapWidget map = new MapWidget(ATLANTA, 10);
				map.setSize("400px", "350px");
				// Add a marker
				map.addControl(new LargeMapControl());
				map.addOverlay(new Marker(ATLANTA));
				map.getInfoWindow().open(map.getCenter(),
						new InfoWindowContent(hotel.getNome()));
				vPanelViewMapHotel.add(map);
			} else {
				vPanelViewMapHotel.add(new HTML(I18nMessages.INSTANCE
						.mapa_hotel_indisponivel()));
			}
		} else {
			vPanelViewMapHotel.add(new HTML(I18nMessages.INSTANCE
					.mapa_hotel_indisponivel()));
		}
	}

}